<%@ page language="java" contentType="text/html; charset=utf-8"%>
<html>
<head>
<%@ include file="/extjs/include/all.jsp"%>
<link href="${pageContext.request.contextPath}/edu.ccut.saturn.manager.dict.impl/extpageModule/page/css/dict.css" rel="stylesheet" type="text/css">
<title>数据字典</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/edu.ccut.saturn.manager.dict.impl/extpageModule/page/js/dictValidate.js">
</script>
</head>
<body>
<div id="dictForm" style="width:100%"></div>
<div id="result" style="width:100%"></div>
</body>
</html>
<script>
var submitFunc;
var submitFuncRole;
Ext.onReady(function(){

  	Ext.QuickTips.init();  
	//-------------------------------------------------------------------------
	// 			查询表单
	//
	//-------------------------------------------------------------------------
	
    var top = new Ext.FormPanel({
        frame:true,//frame为false 背景为白色 
        title: '查询字典',
        bodyStyle:'padding:5px 5px 0',
        collapsible:true,
        renderTo:'dictForm', //选择div
        items: [{
            layout:'column',
            items:[{
                columnWidth:.5,
                layout: 'form', 
                items: [{
                    xtype:'textfield',
                    fieldLabel: '数据字典',
                    name: 'key',
                    id:'key',
                    vtype: 'isNumberAlphaUnderline',
                    anchor:'95%'
                }]
                
            },{
                columnWidth:.5,
                layout: 'form',
                items: [{
                    xtype:'textfield',
                    fieldLabel: '数据字典名称',
                    name: 'name',
                    id: 'name',
                    vtype: 'isNumberAlphaUnderlineChinese',
                    anchor:'95%'
                }]
            }]
        }],

        buttons: [{
            text: '查询',
            handler:function(){
            	if (top.form.isValid()) {
		       		ds.load({params:{						
		       				    start:0, limit:10,
								key:Ext.get("key").dom.value,
								name:Ext.get("name").dom.value
								}}); 
		
		       	grid.getView().refresh();
       			} else {
       				Ext.MessageBox.alert('警告','对不起,您的页面输入有误');
       			}
            }
        }]
    });
	
	
	//-------------------------------------------------------------------------
	// 			下面的是表格
	//
	//-------------------------------------------------------------------------
	
	var sm = new Ext.grid.CheckboxSelectionModel();
	var resultWidth = Ext.get("result").getWidth();
	var cm = new Ext.grid.ColumnModel([ 
	    new Ext.grid.RowNumberer(), //table's index id
	    sm, 
	        {header:'数据字典',dataIndex:'key',width:resultWidth*0.32},  
	        {header:'数据字典名称',dataIndex:'name',width:resultWidth*0.32,sortable:true}, 
	        {header:'操作',dataIndex:'',width:resultWidth*0.32,sortable:true,renderer:function(value, p, record){
	        	return String.format("<a href=\"${pageContext.request.contextPath}/edu.ccut.saturn.manager.dict.impl/extpageModule/page/editDictType.jsp?key={0}&name={1}\">修改</a>" +
	        	　"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"${pageContext.request.contextPath}/edu.ccut.saturn.manager.dict.impl/extpageModule/paramPage/dictParamList.jsp?key={0}\">详细信息</a>", record.data.key,record.data.name);
	        }}
	    ]); 
	    cm.defaultSortable = true; 
	 	var ds = new Ext.data.Store({ 
	        proxy: new Ext.data.HttpProxy({
	        	url:'${pageContext.request.contextPath}/edu.ccut.saturn.manager.dict.impl::/extDictTypeModule/action/QueryDictTypeList.action'
	        }), 
	        reader: new Ext.data.JsonReader({ 
	                totalProperty: 'count',
	                root: 'result' 
		    }, 
		    [ 
		        {name: 'key',mapping:'type'}, 
		        {name: 'name',mapping:'name'} 
		    ])
	    }); 
			       
	    var grid = new Ext.grid.GridPanel({ 
	    el: 'result', 
	    title:'数据字典', 
	  //  height:350, 
	    autoHeight:true,
	    stripeRows: true,
	    collapsible:true,
	    bodyStyle:'width:100%',
	    trackMouseOver:false, 
	    loadMask: {msg:'正在加载数据，请稍侯……'}, 
	    store:ds, 
	    cm: cm, 
	    sm:sm, 
	    tbar: [{
            text:'新增数据字典',
            tooltip:'新增数据字典',
            iconCls:'add',
            handler: function(){
            	window.location = '${pageContext.request.contextPath}/edu.ccut.saturn.manager.dict.impl/extpageModule/page/addDictType.jsp'
            }
        }, '-',{
            text:'删除数据字典',
            tooltip:'删除数据字典',
            iconCls:'remove',
            handler : remove
        }],
	    bbar: new Ext.PagingToolbar({ 
	            pageSize: 10, 
	            store: ds, 
	            displayInfo: true, 
	            displayMsg: '当前显示 {0} - {1}条记录 /共 {2}条记录', 
	            emptyMsg: "没有数据显示" 
	    }) 
	}); 
			
	ds.load({params:{start:0, limit:10}}); 
    grid.render(); 	
    
	ds.on('beforeload',function(){
	      Ext.apply(
	      this.baseParams,
	      {
	                key:Ext.get("key").dom.value,
				    name:Ext.get("name").dom.value
	      });
	      if(!(top.form.isValid())){
	      	Ext.MessageBox.alert('警告','对不起，您的查询条件有误');
    		return false;
    	 }
    	}	
    );
			    
	//--------------------------------------------------------------------------------------------
	//						删除用户
	//
	//
	//
	//
	//--------------------------------------------------------------------------------------------
  	function remove(){
  	
  		arr_Records = sm.getSelections();
	    if (arr_Records.length == 0) {
	        Ext.MessageBox.alert('警告', '最少需要选择一条记录!');
	    } else {
			Ext.MessageBox.confirm('确认', '确认删除所选信息?', delDictType);
		}
	}
	function delDictType(btn){

        if(btn == 'yes'){
	        arr_Records = sm.getSelections();
	        var delStr = ''; 		 
	   	   	for (var i = 0, len = arr_Records.length; i < len; i++){    
	   	   	  	 
	   	   	  	 delStr += arr_Records[i].data.key;  
	   	   	  	 delStr += ',' ;	
			} 
		    if(delStr.length > 0){
 					delStr = delStr.substring(0,delStr.length - 1) ;
			}
			Ext.Ajax.request({
			     method : 'POST',                             //发送方式.'POST'或'GET',一般是'POST'
			     url: '${pageContext.request.contextPath}/edu.ccut.saturn.manager.dict.impl::/extDictTypeModule/action/DeleteDictType.action',                  //发送到页面
			     success:function(request){                   //发送成功的回调函数
			       var myResult = Ext.util.JSON.decode(request.responseText);
			       if (myResult.delSucc == 'true') {
	                   Ext.Msg.alert('信息','删除成功', function(){
			       	       ds.load({params:{start:0, limit:10}}); //重新刷新table
			           });        //弹出对话框			
	               } else {
		               Ext.MessageBox.show({
		               title: '删除失败',
		               msg: '对不起，删除失败！可能与数据库连接发生了错误！',
		               buttons: Ext.MessageBox.OK,
		               icon: Ext.MessageBox.ERROR
	                   });
	               }			       
			    },
			    failure:function(){                          //发送失败的回调函数
			       Ext.Msg.alert("错误", "与后台联系的时候出现了问题");
			    },
			    params:{
			       list:delStr 
			    } 
	     	});       	
        } 		  
    }; 
	});
</script>